package com.yuan.algorithms.base01;

import java.util.Scanner;

/**
 * @author YouYuan
 * <br>E-mail:1265161633@qq.com
 * <br>创建时间：2015年9月29日 下午1:25:47
 * <br>说明:
 */
public class 曲折填数 {
	
	static Scanner in = new Scanner(System.in);
	static final int MAX = 10000;
	static int[][] map = new int[MAX][MAX];
	public static void main(String[] args) {
		while(in.hasNext()) {
			int n = in.nextInt();
			int x = 0, y = 0;
			boolean mark = true;
			for (int i = 1, size = n * n; i <= size; i++) {
				map[x][y] = i;
				if (mark) {
					--x;
					++y;
					if (y>=n && x < 0) {
						y -= 1;
						x += 2;
						mark = !mark;
						continue;
					}
					if (x < 0) {
						x += 1;
						mark = !mark;
					} else if (y >= n) {
						x += 2;
						y -= 1;
						mark = !mark;
					}
				} else {
					++x;
					--y;
					if (x>=n && y < 0) {
						x -= 1;
						y += 2;
						mark = !mark;
						continue;
					}
					if (y < 0) {
						y += 1;
						mark = !mark;
					} else if (x >= n) {
						y += 2;
						x -= 1;
						mark = !mark;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					System.out.print(map[i][j]+"\t");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}
